package cn.cxion.chat.app.view;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.cxion.chat.R;
import cn.cxion.chat.app.constant.Constant;
import cn.cxion.chat.app.util.CountDownTimerUtils;
import cn.cxion.chat.app.util.LogUtil;

public class ChangePassWordView {

    private View view;
    private Activity activity;
    private int classType;
    private ViewHolder holder;

    public ChangePassWordView(Context context, int classType) {
        view = LayoutInflater.from(context).inflate(R.layout.view_changepwd, null);
        activity = (Activity) context;
        this.classType = classType;
        init();
    }

    public View getView() {
        return view;
    }

    public void init() {
         holder = new ViewHolder(view);
        viewControl();

        holder.tvSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
        holder.tvGetverification.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CountDownTimerUtils.getInstant(holder.tvGetverification, 15000, 1000).start();
            }
        });
    }

    private void viewControl() {
        initView();
        switch (classType) {
            case Constant.CHANGEBYPHONEVIEW:
                holder.etPhone.setVisibility(View.VISIBLE);
                holder.ll_verification.setVisibility(View.VISIBLE);
                holder.etNewpwd1.setVisibility(View.VISIBLE);
                break;
            case Constant.CHANGEBYOLDPWDVIEW:
                holder.etOldpwd.setVisibility(View.VISIBLE);
                holder.etNewpwd1.setVisibility(View.VISIBLE);
                holder.etNewpwd2.setVisibility(View.VISIBLE);
                break;
            default:
                break;
        }
    }
    private void initView(){
        holder.etPhone.setVisibility(View.GONE);
        holder.ll_verification.setVisibility(View.GONE);
        holder.etOldpwd.setVisibility(View.GONE);
        holder.etNewpwd1.setVisibility(View.GONE);
        holder.etNewpwd2.setVisibility(View.GONE);
    }


    static class ViewHolder {
        @Bind(R.id.et_phone)
        AutoCompleteTextView etPhone;
        @Bind(R.id.et_verification)
        EditText etVerification;
        @Bind(R.id.tv_getverification)
        TextView tvGetverification;
        @Bind(R.id.et_oldpwd)
        EditText etOldpwd;
        @Bind(R.id.et_newpwd1)
        TogglePasswordVisibilityEditText etNewpwd1;
        @Bind(R.id.et_newpwd2)
        TogglePasswordVisibilityEditText etNewpwd2;
        @Bind(R.id.tv_submit)
        TextView tvSubmit;
        @Bind(R.id.ll_verification)
        LinearLayout ll_verification;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
